package com.lh.Config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@EnableConfigurationProperties
@Configuration
public class ThreadConfig {

    @Autowired
    private ThreadPool threadPool;

    @Bean
    public Executor executor(){
        ThreadPoolExecutor executor = new ThreadPoolExecutor(threadPool.getCorePoolSize(),
                threadPool.getMaximumPoolSize(),
                threadPool.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(10),
                new ThreadPoolExecutor.DiscardOldestPolicy());
        return executor;
    }
}
